package design.principle;

import com.alibaba.fastjson.JSON;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * @program JavaBase
 * @description: 里氏替换原则
 * @author: zhanglu
 * @create: 2020-03-25 17:00:00
 */
public class RichterReplacement {

    public static void main(String[] args) {

        //1.子类必须完全实现父类的方法
//        GaoTai gaoTai = new GaoTai();
//        gaoTai.setDuanXinPt(new Sms());
//        gaoTai.send("1");


        //2、子类可以有自己的个性
//        Handle handle01 = new Handle(new Child01());
//        handle01.ss();
//
//        Handle handle02 = new Handle((Child01) new Parent());   //java.lang.ClassCastException
//        handle01.ss();


        //3.覆盖或实现父类的方法时输入参数可以被放大
//        Map<String, String> m1 = new HashMap<>();
//        m1.put("Map", "1");
//
//        HashMap<String, String> m2 = new HashMap<>();
//        m2.put("HashMap", "1");
//        
//        Sms sms = new Sms();
//        sms.str(m2);

//        Child01 child01 = new Child01();
//        String res = child01.res();
//
//        System.out.println(res);
    }

}

abstract class DuanXinPt{

    abstract void sendSms();

    public void str(HashMap map){
        System.out.println("DuanXinPt" + JSON.toJSONString(map));
    }

}

class Sms extends DuanXinPt{

    @Override
    void sendSms() {
        System.out.println("发送短信");
    }

    /**
     * 重载
     * @param map
     */
    public void str(Map map) {
        System.out.println("Sms" + JSON.toJSONString(map));
    }

}

class Mms extends DuanXinPt{

    @Override
    void sendSms() {
        System.out.println("发送彩信");
    }

    /**
     * 覆盖
     * @param map
     */
    @Override
    public void str(HashMap map) {
        super.str(map);
    }
}

class GaoTai{

    public DuanXinPt duanXinPt;

    public void setDuanXinPt(DuanXinPt duanXinPt){
        this.duanXinPt = duanXinPt;
    }

    public void send(String phone){
        System.out.println("号码：" + phone);
        duanXinPt.sendSms();
    }

}

class Parent{

    public String res(){
        System.out.println("111");
        return "111";
    }

}

class Child01 extends Parent{

    public void handle(){
        System.out.println("Child01:handle");
    }

    @Override
    public String res() {
        return (String) new Object();
    }

}

class Handle{

    private Child01 child01;

    public Handle(Child01 child01){
        this.child01 = child01;
    }

    public void ss(){
        child01.handle();
    }



}






